package com.example.androidvelostar;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class StationsActivity extends Activity {
	public static final String NOMDISTRICT = "nomDistrict";
	ArrayList<Station> lesStations;
	ArrayAdapter<Station> unAdaptateur;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_stations);
		initialisations();
	}

	private void initialisations() {
		ListView listViewStations;
		Intent uneIntention;
		String leDistrict;

		uneIntention = getIntent();
		leDistrict = uneIntention.getStringExtra(NOMDISTRICT);
		try {
			lesStations = Passerelle.getLesStations(leDistrict);
			unAdaptateur = new ArrayAdapter<Station>(this, android.R.layout.simple_list_item_1, lesStations);
			listViewStations = (ListView) findViewById(R.id.listViewStations);
			listViewStations.setAdapter(unAdaptateur);
		}
		catch (Exception ex) {
			Toast.makeText(this, R.string.erreurStations, Toast.LENGTH_LONG).show();
		}		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.stations, menu);
		return true;
	}

}
